home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d10 / pros15.arc / PROS15.EXE / PROCVSPD.C < prev    next >
Text File  |  1991-04-07  |  4KB  |  141 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2.  *          Filename : PROCVSPD.C                                          *
  3.  *         Version : 1.2                                                 *
  4.  *         Project : PRO$TOCK: Download Stock Quotes from Prodigy        *
  5.  *          Author : Philippe Rabergeau                                  *
  6.  *       Copyright : (C) 1990 by Philippe Rabergeau                      *
  7.  *          Compiler : Borland Turbo C++ Version 1.0 Large model/Byte align*
  8.  *     Creation date : 06/28/90                                            *
  9.  * Modification date : 11/04/90                                            *
  10.  *     Description : Conversion of Prodigy Stock Quotes format           *
  11.  *          Comments : Not for Commercial Use                              *
  12.  *                                          *
  13.  * SPD like Spreadsheet format                                             *
  14.  *                                                                         *
  15.  * PRO$TOCK registered users, freeware and shareware authors are allowed   *
  16.  * to modify and incorporate this source code in any type of program.      *
  17.  * Please inform the author of any development in association           *
  18.  * with this source code:    Philippe Rabergeau                         *
  19.  *                             512 E. 5th St.  #9                         *
  20.  *                             New York, NY 10009                         *
  21.  *                       Prodigy ID WNWB44A                       *
  22.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  23.  
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <conio.h>
  29.  
  30. char extract_str[7][20];
  31. double extract_val[7];
  32.  
  33. /***********************************************************/
  34. /* Change only this part for other format                  */
  35. /***********************************************************/
  36.  
  37. int result_start(FILE *out)    /* put header here */
  38. {
  39.   return(1);
  40. }
  41.  
  42. int result_end(FILE *out)
  43. {
  44.   return(1);
  45. }
  46.  
  47. int result_save(FILE *out)
  48. {
  49. int i;
  50.   for(i=0;i<2;i++) fprintf(out,"\"%s\",",extract_str[i]);
  51.   for(;i<5;i++) fprintf(out,"%s,",extract_str[i]);
  52.   if ((strchr(extract_str[5],'/')!=NULL)||(extract_str[5][0]==0))
  53.        fprintf(out,"\"%s\"",extract_str[5]);
  54.   else fprintf(out,"%s",extract_str[5]);
  55.   fprintf(out,"\r\n");
  56.   return(1);
  57. }
  58.  
  59. /***********************************************************/
  60.  
  61. int convert(FILE *in,FILE *out)
  62. {
  63. int i;
  64. char s[90];
  65.   result_start(out);
  66.   fgets(s,83,in);
  67.   fgets(s,83,in);
  68.   fgets(s,83,in);
  69.   fgets(s,83,in);
  70.   fgets(s,83,in);
  71.   while(fgets(s,83,in)!=NULL)
  72.   {
  73.     s[strlen(s)-1]=0;
  74.     if ((s[0]>' ')&&(s[0]!='-'))
  75.     {
  76.       for(i=0;i<6;i++) extract_str[i][0]=0;
  77.       sscanf(s,"%s %s %s %s %s %s",extract_str[0],extract_str[1],extract_str[2]
  78.            ,extract_str[3],extract_str[4],extract_str[5]);
  79.       for(i=2;i<6;i++) extract_val[i]=atof(extract_str[i]);
  80.       result_save(out);
  81.     }
  82.     else break;
  83.   }
  84.   result_end(out);
  85.   return(1);
  86. }
  87.  
  88. /*--- Main program ---*/
  89.  
  90. void main(int argc, char *argv[])
  91. {
  92. int ret=1;
  93. char fname_in[64];
  94. char fname_out[64];
  95. FILE *fp_in;
  96. FILE *fp_out;
  97.   clrscr();
  98. /*--- definition of input and output filename ---*/
  99.   if (argc<2) strcpy(fname_in,"PRODIGY.ASC");
  100.   else strcpy(fname_in,argv[1]);
  101.   if (argc<3) strcpy(fname_out,"PRODIGY.SPD");
  102.   else
  103.   {
  104.     strcpy(fname_out,argv[2]);
  105.     if (fname_out[strlen(fname_out)-1]=='\\') strcat(fname_out,"PRODIGY.SPD");
  106.     else if (fname_out[strlen(fname_out)-1]=='.') strcat(fname_out,"SPD");
  107.   }
  108.  
  109. /*--- conversion of filename in upper case ---*/
  110.   strupr(fname_in);
  111.   strupr(fname_out);
  112.  
  113.   printf("Convert Prodigy Stock Quotes into Spreadsheet format\n\n");
  114.   printf("Converting the file '%s'\n",fname_in);
  115.   printf("Result saved into   '%s'\n",fname_out);
  116.  
  117. /*--- Open files ---*/
  118.   if ((fp_in=fopen(fname_in,"rt"))==NULL)
  119.   {
  120.     printf("ERROR: Can't open input file '%s'\n",fname_in);
  121.     ret=0;
  122.   }
  123.   else
  124.   {
  125.     if ((fp_out=fopen(fname_out,"w+b"))==NULL)
  126.     {
  127.       printf("ERROR: Can't creat output file '%s'\n",fname_out);
  128.       ret=0;
  129.     }
  130.     else
  131.     {
  132.  
  133. /*--- Conversion in progress ---*/
  134.       convert(fp_in,fp_out);
  135.       fclose(fp_out);
  136.     }
  137.     fclose(fp_in);
  138.   }
  139.   exit(ret);
  140. }
  141.